import { reqGetCategory1Data, reqGetCategory2Data, reqGetCategory3Data } from "@/api/product/attr"
export default {
    namespaced: true,
    state: {
        category1Id: undefined,
        category2Id: undefined,
        category3Id: undefined,
        category1List: [],
        category2List: [],
        category3List: [],
    },
    actions: {
        //获取一级分类数据
        async getCategory1ListData({ commit }) {
            const result = await reqGetCategory1Data()
            if (result.code === 200) {
                commit('GetCategory1List', result.data)
            }
        },
        //获取二级分类数据
        async getCategory2ListData({ commit }, cateId1) {
            const result = await reqGetCategory2Data(cateId1)
            if (result.code === 200) {
                commit('GetCategory2List', { result, cateId1 })
            }
        },
        //获取三级分类数据
        async getCategory3ListData({ commit }, cateId2) {
            const result = await reqGetCategory3Data(cateId2)
            if (result.code === 200) {
                commit('GetCategory3List', { result, cateId2 })
            }
        },
        //设置三级分类id
        async setCategory3Id({ commit }, cateId3) {
            commit('SetCategory3Id', cateId3)
        }
    },
    mutations: {
        GetCategory1List(state, data) {
            state.category1List = data
        },
        GetCategory2List(state, { result, cateId1 }) {
            state.category2List = result.data
            state.category1Id = cateId1
            state.category2Id = undefined
            state.category3Id = undefined
            state.category3List = []
        },
        GetCategory3List(state, { result, cateId2 }) {
            state.category3List = result.data
            state.category2Id = cateId2
            state.category3Id = undefined
        },
        SetCategory3Id(state, cateId3) {
            state.category3Id = cateId3
        }
    },

}